package com.cool.reggie.modules.orders.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cool.reggie.modules.orders.dto.OrderDto;
import com.cool.reggie.modules.orders.entity.OrdersEntity;
import com.cool.reggie.modules.orders.service.OrdersService;
import com.cool.reggie.utils.ResultData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author 1950735817@qq.com
 * @since 2022-07-20
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    @PostMapping("/submit")
    public ResultData submit(@RequestBody OrdersEntity ordersEntity) {

        ordersService.submitOrder(ordersEntity);
        return ResultData.ok();
    }

    @GetMapping("/userPage")
    public ResultData userPage(@RequestParam("page") Long page, @RequestParam Long pageSize) {

        Page<OrderDto> pageResult = ordersService.queryList(new Page<OrdersEntity>(page, pageSize));


        return ResultData.ok(pageResult);
    }


}
